package com.wzdigit.wms.wms.config.webservice;

import javax.xml.ws.Endpoint;

import com.wzdigit.wms.wms.webservice.OmsShipWebserviceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


// ~ File Information
/**
 * @author shuaic
 * @date 2021年8月30日 下午3:12:00
 * 类说明：webservice发布，默认访问地址为：localhost:8080/services/helloWord?wsdl
 *
 */
@Configuration
public class WebserviceConfig {

    // ~ Fields
    @Autowired
    private OmsShipWebserviceImpl webservice;//接口实现类

    // ~ Methods

    /**
     * 此方法作用是改变项目中服务名的前缀名，此处127.0.0.1或者localhost不能访问时，请使用ipconfig查看本机ip来访问
     * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8080/services/user?wsdl
     * 去掉注释后：wsdl访问地址为：http://127.0.0.1:8080/soap/user?wsdl
     * @return
     */


    /*  @Bean
      public ServletRegistrationBean dispatcherServlet() {
          return new ServletRegistrationBean(new CXFServlet(), "/service/*");
      }*/

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public Endpoint endpoint() {
        System.out.println("发布服务");
        EndpointImpl endpoint=new EndpointImpl(springBus(), webservice);
        //endpoint.getInInterceptors().add(new Clientlogin)

        endpoint.publish("/helloWorld");//访问地址
        //endpoint.getInInterceptors().add(new AuthInterceptor());//添加校验拦截器

        return endpoint;
    }

}
